package de.servicezombie.tests.spring;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Date;
import java.util.Locale;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

public class BeanFactoryOnlyApplicationContext implements ApplicationContext {

	private BeanFactory beanFactory;
	private ResourceLoader resourceLoader;
	private long started;

	public BeanFactoryOnlyApplicationContext(BeanFactory beanFactory) {
		super();
		this.beanFactory = beanFactory;
		resourceLoader = new DefaultResourceLoader();
		started = new Date().getTime();
	}

	@Override
	public boolean containsBeanDefinition(String arg0) {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public <A extends Annotation> A findAnnotationOnBean(String arg0, Class<A> arg1) {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public int getBeanDefinitionCount() {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public String[] getBeanDefinitionNames() {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public String[] getBeanNamesForType(@SuppressWarnings("rawtypes") Class arg0) {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public String[] getBeanNamesForType(@SuppressWarnings("rawtypes") Class arg0, boolean arg1, boolean arg2) {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public <T> Map<String, T> getBeansOfType(Class<T> arg0) throws BeansException {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public <T> Map<String, T> getBeansOfType(Class<T> arg0, boolean arg1, boolean arg2) throws BeansException {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> arg0) throws BeansException {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public boolean containsBean(String arg0) {
		return beanFactory.containsBean(arg0);
	}

	@Override
	public String[] getAliases(String arg0) {
		return beanFactory.getAliases(arg0);
	}

	@Override
	public Object getBean(String arg0) throws BeansException {
		return beanFactory.getBean(arg0);
	}

	@Override
	public <T> T getBean(Class<T> arg0) throws BeansException {
		return beanFactory.getBean(arg0);
	}

	@Override
	public <T> T getBean(String arg0, Class<T> arg1) throws BeansException {
		return beanFactory.getBean(arg0, arg1);
	}

	@Override
	public Object getBean(String arg0, Object... arg1) throws BeansException {
		return beanFactory.getBean(arg0, arg1);
	}

	@Override
	public Class<?> getType(String arg0) throws NoSuchBeanDefinitionException {
		return beanFactory.getType(arg0);
	}

	@Override
	public boolean isPrototype(String arg0) throws NoSuchBeanDefinitionException {
		return beanFactory.isPrototype(arg0);
	}

	@Override
	public boolean isSingleton(String arg0) throws NoSuchBeanDefinitionException {
		return beanFactory.isSingleton(arg0);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public boolean isTypeMatch(String arg0, Class arg1) throws NoSuchBeanDefinitionException {
		return beanFactory.isTypeMatch(arg0, arg1);
	}

	@Override
	public boolean containsLocalBean(String arg0) {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public BeanFactory getParentBeanFactory() {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public String getMessage(MessageSourceResolvable arg0, Locale arg1) throws NoSuchMessageException {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public String getMessage(String arg0, Object[] arg1, Locale arg2) throws NoSuchMessageException {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public String getMessage(String arg0, Object[] arg1, String arg2, Locale arg3) {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public void publishEvent(ApplicationEvent arg0) {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public Resource[] getResources(String arg0) throws IOException {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public ClassLoader getClassLoader() {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public Resource getResource(String arg0) {
		return resourceLoader.getResource(arg0);
	}

	@Override
	public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public String getDisplayName() {
		return "BeanFactoryBased ApplicationContext";
	}

	@Override
	public String getId() {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public ApplicationContext getParent() {
		throw new UnsupportedOperationException("this method is not supported by this implementation");
	}

	@Override
	public long getStartupDate() {
		return started;
	}

}
